# 5. 查询数据
import sqlite3

from mysql.create_db import cursor

try:
    cursor.execute("SELECT * FROM users")
    # 获取所有结果
    all_users = cursor.fetchall()
    print("\n所有用户：")
    for user in all_users:
        print(user)  # 输出格式：(id, name, age, email)

    # 条件查询
    cursor.execute("SELECT name, age FROM users WHERE age > 28")
    print("\n年龄大于28的用户：")
    for user in cursor.fetchall():
        print(user)
except sqlite3.Error as e:
    print(f"查询失败：{e}")